/*
 * MatrixCompare.java
 *
 * Created on July 3, 2005, 10:21 AM
 *
 * (C) R. Alexander Milowski alex@milowski.com
 */

package com.milowski.monos.tools;

import java.io.*;
import com.milowski.monos.binomial.*;

/**
 *
 * @author R. Alexander Milowski
 */
public class MatrixCompare
{
   
   /** Creates a new instance of MatrixCompare */
   public MatrixCompare()
   {
   }
   private String arrayToString(short [] values) {
      StringBuffer sb = new StringBuffer();
      for (int i=0; i<values.length; i++) {
         if (i!=0) {
            sb.append(' ');
         }
         sb.append(values[i]);
      }
      return sb.toString();
   }
   
   
   public static void compare(String prefix,MatrixBasis m1,MatrixBasis m2) {
      int m1RowCount = m1.getRowCount();
      int m2RowCount = m2.getRowCount();
      int colCount = m1.getColumnCount();
      for (int row=0; row<m1RowCount; row++) {
         boolean found = false;
         for (int i=0; !found && i<m2RowCount; i++) {
            int c;
            for (c=0; c<colCount && m1.get(row, c)==m2.get(i,c); c++);
            if (c==colCount) {
               found = true;
            }
         }
         if (!found) {
            boolean inverted = false;
            for (int i=0; !found && i<m2RowCount; i++) {
               int c;
               for (c=0; c<colCount && m1.get(row, c)==(-m2.get(i,c)); c++);
               if (c==colCount) {
                  inverted = true;
               }
            }
            if (inverted) {
               System.err.println('-'+prefix+m1.rowToString(row));
            } else {
               System.err.println(' '+prefix+m1.rowToString(row));
            }
         }
      }
   }
   
   public static void main(String [] args)
   {
      try {
         FileReader input1 = new FileReader(args[0]);
         FileReader input2 = new FileReader(args[1]);
         MatrixBasis m1 = MatrixBasis.read(input1);
         MatrixBasis m2 = MatrixBasis.read(input2);
         input1.close();
         input2.close();
         if (m1.getColumnCount()!=m2.getColumnCount()) {
            System.err.println("Column counts are not equal.");
            System.exit(1);
         }
         compare("< ",m1,m2);
         compare("> ",m2,m1);
      } catch (Exception ex) {
         ex.printStackTrace();
      }
      
   }
   
}
